package org.ws.task.builder;

import org.ws.task.model.TaskConfig;

public final class TaskConfigBuilder {

    private TaskConfig taskConfig;
    private TaskBuilder parent;


    public TaskConfigBuilder(String name,TaskBuilder parent) {
        this.parent = parent;
        this.taskConfig = new TaskConfig(name);
    }

    public TaskConfigBuilder chunk(Integer chunk) {
        this.taskConfig.setChunk(chunk);
        return this;
    }

    public TaskConfigBuilder workerNum(Integer workerNum) {
        this.taskConfig.setWorkerNum(workerNum);
        return this;
    }

    public TaskConfigBuilder dispatchStrategy(TaskConfig.DispatchStrategy dispatchStrategy) {
        this.taskConfig.setDispatchStrategy(dispatchStrategy);
        return this;
    }

    public TaskConfigBuilder fetchTimeout(int fetchTimeout) {
        this.taskConfig.setFetchTimeout(Long.valueOf(fetchTimeout));
        return this;
    }

    public TaskConfigBuilder leaderProcess(Boolean leaderProcess) {
        this.taskConfig.setLeaderProcess(leaderProcess);
        return this;
    }

    public TaskConfigBuilder sendModel(TaskConfig.SendModel sendModel){
        this.taskConfig.setSendModel(sendModel);
        return this;
    }

    public <T> PullTaskBuilder<T> pull(){
        return this.parent.pull(this.taskConfig);
    }

    public <T> PushTaskBuilder<T> push(){
        return this.parent.push(this.taskConfig);
    }
}
